package za.ac.cput.peterjohn.DesignPatternPrincipals.Structural.Composite.Model;

import java.util.ArrayList;
import java.util.List;

public class Composite implements Component
{
    List<Component> components = new ArrayList<Component>();
    
    @Override
    public String sayHello()
    {
        String response = null;
        
        for(Component component : components)
            response += component.sayHello();
        
        return response;
    }

    @Override
    public String sayGoodbye() 
    {
        String response = null;
        
        for(Component component : components)
            component.sayGoodbye();
        return response;
    }
    
    public void add(Component component){ components.add(component); }
    
    public void remove(Component component){ components.remove(component); }

    public List<Component> getComponents() { return components; }
    
    public Component getComponent(int index){ return components.get(index); }

}